﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data.OleDb

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class tagger
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function getTagsFromPrefix(ByVal prefix As String) As String()
        Dim conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("PlacesConnectionString").ToString())
        conn.Open()
        Dim sql As String = "SELECT TagName FROM Tags WHERE TagName LIKE @prefixText"
        prefix = Replace(prefix, "%", "")
        prefix = prefix & "%"
        Dim cmd = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@prefixText", prefix)
        Dim tagDBReader = cmd.ExecuteReader()
        Dim foundTagsList As New List(Of String)
        If tagDBReader.HasRows Then
            While tagDBReader.Read()
                foundTagsList.Add(tagDBReader("TagName"))
            End While
        End If
        Return foundTagsList.ToArray()
    End Function

End Class